001 /** 002 * Created by IntelliJ IDEA. 003 * User: Wei Wang 004 * Date: Nov 28, 2002 005 * Time: 10:23:35 AM 006 */ 007 008 package EVolve.visualization.XYViz.ValRefViz; 009 010 import EVolve.visualization.*; 011 import EVolve.util.painters.BarChartPainter; 012 import EVolve.data.*; 013 import EVolve.Scene; 014 015 import javax.swing.*; 016 017 public class BarChartViz extends ValueReferenceVisualization{ 018 private static JMenuItem selectionMenu[] = null; 019 private JMenuItem itemSelectOccurredEntities; 020 021 public void makeSelection() { 022 int y1 = canvas.getEndY(); 023 int y2 = canvas.getStartY(); 024 025 if (dataSourceId != Scene.getDataSourceManager().getCurrentDataSourceId()) { 026 Scene.showErrorMessage("The active data source used currently is different from \n" + 027 "this visualization, please choose \"" + 028 Scene.getDataSourceManager().getUsedDataSourceName(dataSourceId)+"\"."); 029 return; 030 } 031 032 if (!normalOrientation) { 033 y1 = canvas.getStartX(); 034 y2 = canvas.getEndX(); 035 } 036 037 if (((y1<0)&&(y2<0)) || ((y1>=yAxis.getEntityNumber())&&(y2>=yAxis.getEntityNumber()))) 038 return; 039 040 if (y1 < 0) { 041 y1 = 0; 042 } 043 044 if (y2 > (yAxis.getEntityNumber() - 1)) { 045 y2 = yAxis.getEntityNumber() - 1; 046 } 047 048 int[] selection = new int[y2 - y1 + 1]; 049 for (int i = y1; i <= y2; i++) { 050 selection[i - y1] = i; 051 } 052 053 yAxis.makeSelection(subjectDefinition.getType(),selection); 054 } 055 056 public void preVisualize() { 057 image = new AutoImage(); 058 installPainter(); 059 timeMap.clear(); 060 } 061 062 public void receiveElement(Element element) { 063 if (element.isOptional()) return; 064 065 long y = yAxis.getField(element); 066 long v = xAxis.getField(element); 067 painter.paint(image,v,y,0); 068 069 } 070 071 public void visualize() { 072 xMax = ((BarChartPainter)painter).getxMax(); 073 074 yAxis.addComparator(new ValueComparator("Value", false, ((BarChartPainter)painter).getValue(), yAxis.getEntityName2IntMap())); 075 sort(); 076 } 077 078 protected void installPainter() { 079 painter = new BarChartPainter(yAxis.getMaxEntityNumber()); 080 } 081 082 public JMenuItem[] createSelectionMenuItem() { 083 if (selectionMenu != null) return selectionMenu; 084 085 itemSelectOccurredEntities = new JCheckBoxMenuItem("Occurred Entities"); 086 itemSelectOccurredEntities.setSelected(true); 087 itemSelectOccurredEntities.setEnabled(false); 088 089 selectionMenu = new JMenuItem[1]; 090 selectionMenu[0] = itemSelectOccurredEntities; 091 092 return selectionMenu; 093 } 094 }